package com.guiwu.gteway.industryapp.Device.module;

import android.content.Context;

import com.google.gson.annotations.SerializedName;
import com.guiwu.gteway.industryapp.R;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created by qiaoguan on 2018/3/31.
 */

public class AlarmBean {

    @SerializedName("triggerName")
    private String alarmName;

    private String content;

    private int value;

    private int handleState;

    private String time;

    private Context context;

    private Date date;

    public AlarmBean(Context context){
        this.context = context;
        date = new Date();
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public String getAlarmName() {
        return alarmName;
    }

    public void setAlarmName(String alarmName) {
        this.alarmName = alarmName;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getHandleState() {
        return handleState == 0 ? context.getString(R.string.alarm_handle_ok)
                                : context.getString(R.string.alarm_handle_no);
    }

    public void setHandleState(int handleState) {
        this.handleState = handleState;
    }

    public Date getTime() {
        if (time == null){
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        try {
            date = format.parse(time);
        }catch (ParseException e){
            e.printStackTrace();
        }
        return date;
    }

    public void setTime(String time) {
        this.time = time;
    }

    @Override
    public String toString() {
        return "报警名称：" + getAlarmName() + " 报警状态：" + getHandleState() + "  报警数值：" + getContent();
    }
}
